package com.topisv.tms.web.stock;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.topisv.tms.entity.stock.CusStock;
import com.topisv.tms.service.stock.CusStockService;
import com.topisv.tms.web.base.BaseController;

/**
 * 库存锁定
 *  Date          Author       Version       Description
 * ----------------------------------------------------------
 *  2014-11-21      CC            1.0           Create
 */
@Controller
@RequestMapping(value = "/v2_storageLock")
public class StorageLockController extends BaseController {
	@Autowired
	private CusStockService cusStockService;

	@RequestMapping(value = "show")
	public String show(Model model) {
		fillSelectValue(model, null);
		return "stock/storageLock";
	}

	@RequestMapping(value = "query",method=RequestMethod.POST)
	public String query(Model model, 
			@RequestParam(value = "warehouseCode") String warehouseCode,
			@RequestParam(value = "customerCode") String customerCode,
			@RequestParam(value = "sku") String sku) {
		List<CusStock> cusStocks = cusStockService.loadStock(warehouseCode, customerCode, sku);
		model.addAttribute("cusStocks", cusStocks);
		fillSelectValue(model, customerCode);
		return "stock/storageLock";
	}
	@RequestMapping(value = "lock",method=RequestMethod.POST)
	@ResponseBody
	public String lock(@RequestBody Long[] cusStocks){
		log.info("{} locked sku {}",getShiroUser().realname,cusStocks);
		return cusStockService.lock(Arrays.asList(cusStocks));
	}
	@RequestMapping(value = "unLock",method=RequestMethod.POST)
	@ResponseBody
	public String unLock(@RequestBody Long[] cusStocks){
		log.info("{} unLock sku {}",getShiroUser().realname,cusStocks);
		return cusStockService.unLock(Arrays.asList(cusStocks));
	}
}
